import type { Plugin } from 'postcss';

type Options = {
  viewportWidth: number;
};
// px to vw
const Options: Options = {
  viewportWidth: 375,
};

export const PxToVw = (options: Options = Options): Plugin => {
  const opt = Object.assign({}, Options, options);

  return {
    postcssPlugin: 'px-to-vw',
    Declaration(node) {
      console.log(node.prop, node.value);
      if (node.value.includes('px')) {
        const value = parseFloat(node.value)
        node.value = (value / opt.viewportWidth * 100).toFixed(2) + 'vw'
      }

    }
  }
}

